package com.xxxy.jsq.action.term;

import com.xxxy.jsq.dao.TermDao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/deleteTermServlet")
public class deleteTermServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");

        TermDao dao = new TermDao();
        String cidStr = request.getParameter("cid");

        if (cidStr != null && !cidStr.isEmpty()) {
            Long cid = Long.parseLong(cidStr);
            String flag = dao.deleteById(cid);
            PrintWriter out = response.getWriter();
            out.print(flag);
            out.flush();
            out.close();
        }
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
